/*
 * ConfLangsPanel.java
 *
 * Created on 4 de septiembre de 2008, 2:46
 */

package r4p_gui;

import java.io.File;
import java.util.ArrayList;

import r4p.GUI.configuration.ConfigGeneral;
import r4p.GUI.configuration.ConfigurationLanguage;

/**
 *
 * @author  nemesis
 */
public class ConfLangsPanel extends javax.swing.JPanel {

    ArrayList<String> langFilenames;
    
    /** Creates new form ConfLangsPanel */
    public ConfLangsPanel() {
        initComponents();
	
	langFilenames = new ArrayList<String>();
	
	ConfigGeneral cg = new ConfigGeneral();
	cg.load();
	cg.searchLanguages();
	this.langFilenames = cg.getLanguages();
	
	for (int i = 0; i < langFilenames.size(); i++) {
	    ConfigurationLanguage cl = new ConfigurationLanguage(cg.getConfigDirLanguages() + File.separator + langFilenames.get(i));
	    System.out.println("file trying to open: " + cg.getConfigDirLanguages() + File.separator + langFilenames.get(i));
	    this.comboBox_lang_selector.addItem(cl.getLanguage());
	    System.out.println("Language added: " + cl.getLanguage());
	}
    }
    
    public void relanguage(ArrayList<String> lang) {
	this.label_lang_title.setText(lang.get(1));
	this.label_lang_selector.setText(lang.get(2));
	this.label_author.setText(lang.get(2));
	this.label_filename.setText(lang.get(3));
	this.label_comments.setText(lang.get(4));
    }
    
    public void setInfo(ArrayList<String> info) {
	this.label_author_info.setText(info.get(0));
	this.lable_filename_info.setText(info.get(1));
	this.label_comments_info.setText(info.get(2));
    }
    
    public String getSelectedLanguage() {
	return this.langFilenames.get(this.getSelectedLanguageIndex());
    }
    
    public int getSelectedLanguageIndex() {
	return this.comboBox_lang_selector.getSelectedIndex();
    }
    
    public void setFlagIcon(String iconFile) {
	this.flagIcon.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/" + iconFile));
	this.flagIcon.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label_language_icon = new javax.swing.JLabel();
        label_lang_title = new javax.swing.JLabel();
        label_lang_selector = new javax.swing.JLabel();
        label_author = new javax.swing.JLabel();
        label_filename = new javax.swing.JLabel();
        label_comments = new javax.swing.JLabel();
        comboBox_lang_selector = new javax.swing.JComboBox();
        label_author_info = new javax.swing.JLabel();
        lable_filename_info = new javax.swing.JLabel();
        label_comments_info = new javax.swing.JLabel();
        flagIcon = new javax.swing.JLabel();

        label_language_icon.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/globe_flags.png")); // NOI18N

        label_lang_title.setFont(new java.awt.Font("DejaVu Sans", 1, 14)); // NOI18N
        label_lang_title.setText("Language Configuration");

        label_lang_selector.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
        label_lang_selector.setText("Select your language:");

        label_author.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
        label_author.setText("Author:");

        label_filename.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
        label_filename.setText("Filename:");

        label_comments.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        label_comments.setText("Comments:");

        comboBox_lang_selector.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboBox_lang_selectorItemStateChanged(evt);
            }
        });

        label_author_info.setFont(new java.awt.Font("DejaVu Sans", 1, 10)); // NOI18N
        label_author_info.setText("John Doe (john.doe@whoknows.com)");

        lable_filename_info.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        lable_filename_info.setText("en_en.lang");

        label_comments_info.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        label_comments_info.setText("English language for Dominus.");

        flagIcon.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/en_en.png")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label_language_icon)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label_lang_title)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(label_lang_selector)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBox_lang_selector, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(label_filename)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lable_filename_info))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(label_author)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label_author_info))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(label_comments)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label_comments_info))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(flagIcon)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(label_language_icon))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(label_lang_title)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label_lang_selector)
                            .addComponent(comboBox_lang_selector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(flagIcon)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label_author)
                            .addComponent(label_author_info))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label_filename)
                            .addComponent(lable_filename_info))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label_comments)
                            .addComponent(label_comments_info))))
                .addContainerGap(59, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void comboBox_lang_selectorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBox_lang_selectorItemStateChanged
    // TODO add your handling code here:
    String auxlang = this.getSelectedLanguage();
    auxlang = auxlang.substring(0, auxlang.length() - 4) + "png";
    System.out.println("loading icon " + auxlang);
    this.setFlagIcon(auxlang);
}//GEN-LAST:event_comboBox_lang_selectorItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboBox_lang_selector;
    private javax.swing.JLabel flagIcon;
    private javax.swing.JLabel label_author;
    private javax.swing.JLabel label_author_info;
    private javax.swing.JLabel label_comments;
    private javax.swing.JLabel label_comments_info;
    private javax.swing.JLabel label_filename;
    private javax.swing.JLabel label_lang_selector;
    private javax.swing.JLabel label_lang_title;
    private javax.swing.JLabel label_language_icon;
    private javax.swing.JLabel lable_filename_info;
    // End of variables declaration//GEN-END:variables

}
